<!DOCTYPE html>
<html>
<head>
	<title>我的订单</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link type="text/css" rel="stylesheet" href="../css/bootstrap.css">
	<link type="text/css" rel="stylesheet" href="../css/style.css">
	<script type="text/javascript" src="../js/jquery.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../layer/layer.js"></script>
	<script type="text/javascript" src="../js/cart.js"></script>
	<script type="text/javascript" src="../js/auth.js"></script>
	<script type="text/javascript" src="../js/CookieShop.js"></script>
</head>
<body>
	<!--header-->
	<div class="header">
        <div class="container">
            <nav class="navbar navbar-default" role="navigation">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <h1 class="navbar-brand"><a href="./index"></a></h1>
                </div>
                <!--navbar-header-->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="./index.html">首页</a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">商品分类<b class="caret"></b></a>
                            <ul class="dropdown-menu multi-column columns-2">
                                <li>
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <h4>商品分类</h4>
                                            <ul class="multi-column-dropdown" id="goodsTypeMenu">
                                                <li><a class="list" href="./goods_list.html">全部系列</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </li>
                        <li><a href="./goodsrecommend_list.html?recommendTypeId=2">热销</a></li>
                        <li><a href="./goodsrecommend_list.html?recommendTypeId=3">新品</a></li>


                    </ul>
                    <!--/.navbar-collapse-->
                </div>
                <!--//navbar-header-->
            </nav>
            <div class="header-info">
                <div class="header-right search-box">
                    <a href="javascript:;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
                    <div class="search">
                        <form class="navbar-form" action="./goods_search.html">
                            <input type="text" class="form-control" name="keyword">
                            <button type="submit" class="btn btn-default" aria-label="Left Align">搜索</button>
                        </form>
                    </div>
                </div>

                <div class="header-right cart">
                    <a href="./goods_cart.html">
                        <span class="glyphicon glyphicon-shopping-cart active" aria-hidden="true"><span class="card_num"></span></span>
                    </a>
                </div>
                <div class="clearfix"> </div>
            </div>
            <div class="clearfix"> </div>
        </div>
    </div>
	<!--//header-->
	<!--cart-items-->
	<div class="cart-items">
		<div class="container">
			<h2>我的订单</h2>
				<table class="table table-bordered table-hover">
				<tr   id="dghead">
					<th width="10%">ID</th>
					<th width="10%">总价</th>
					<th width="20%">商品详情</th>
					<th width="30%">收货信息</th>
					<th width="10%">订单状态</th>
					<th width="10%">支付方式</th>
					<th width="10%">下单时间</th>
				</tr>
				<tbody id="dgcontent">
				</tbody>
				</table>
		</div>
        <div style='text-align:center;'>
            <a class='btn btn-info' id="first" href="javascript:first()">首页</a>
            <a class='btn btn-info' id="prev" href="javascript:prev()">上一页</a>
            <h3 style='display:inline;'>[<span id="currentPage"></span>/<span id="totalPage"></span>]</h3>
            <h3 style='display:inline;'>[<span id="recordsCount"></span>]</h3>
            <a class='btn btn-info' id="next" href="javascript:next()">下一页</a>
            <a class='btn btn-info' id="last" href="javascript:last()">尾页</a>
            <input type='text' class='form-control' id="current" style='display:inline;width:60px;'/><a class='btn btn-info' href='javascript:void(0);' onclick='jump()'>GO</a>
        </div>
	</div>
	<!--//cart-items-->
	<!--footer-->
	<div class="footer">
        <div class="container">
            <div class="text-center">

            </div>
        </div>
    </div>
	<!--//footer-->
</body>
<script type="text/javascript">
var mypage = 1;
var myrows = 8;
var currentPage = 1;
var pageCount = 1;
$(document).ready(function(){
  translateGoodses = translateListActiveGoodses();
  countMyCart();
  genGoodsTypesMenu();
  decorateMainMenu("order");
  loadDataGrid(mypage,myrows);
});

function loadDataGrid(page,rows){
	$.ajax({
		type:"post",
		url: "../../custcontroller/custOrderCustController/order_list",
		data: JSON.stringify({
			"page":page,
			"rows":rows,
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			debugger;
			if ( data.rows !=null ){
		        $("#dgcontent").html("");
                configPageControls(data.totalPage,data.pageNumber,data.totalCount);
                for (let i=0;i<data.rows.length;i++){
    				appendGridRow(data.rows[i]);
				}
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function appendGridRow(row){
  var rowStr = "<tr>\n"+
			    "<td><p>"+row.id+"</p></td>\n"+
				"<td><p>"+row.total+"</p></td>\n"+
				"<td>\n"+
				genOrderItems(row.id) +
				"</td>\n"+
				"<td>\n"+
				"<p>"+row.name+"</p>\n"+
				"<p>"+row.phone+"</p>\n"+
				"<p>"+row.address+"</p>\n"+
				"</td>\n"+
				"<td>\n"+
				"<p>\n"+
				genOrderStatus(row.statusId)+
                "</p>\n"+
				"</td>\n"+
				"<td>\n"+
				"<p>\n"+
				genOrderPayType(row.payTypeId)+
				"</p>\n"+
				"</td>\n"+
				"<td><p>"+row.orderDateTime+"</p></td>\n"+
				"</tr>\n";
  $("#dgcontent").append(rowStr);
}

function genOrderItems(custOrderId){
  var rowStr = "";
  $.ajax({
		type:"post",
		url: "../../custcontroller/orderItemCustController/listMyOrderItems",
		data: JSON.stringify({
			"custOrderId":custOrderId,
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		async:false,
		success: function(data, textStatus) {
			debugger;
			if ( data.rows !=null ){
			   for (let i=0;i<data.rows.length;i++){
                    rowStr = rowStr +"<p>"+ translateGoods(data.rows[i].goodsId)+"("+data.rows[i].price+") x "+data.rows[i].amount+"</p>\n";
				}
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
    return rowStr;
}

function genOrderStatus(statusId){
  var rowStr = "";
  if (statusId == 1) rowStr = "<span style=\"color:red;\">未付款</span>";
  else if (statusId == 2) rowStr = "<span style=\"color:red;\">已付款</span>";
  else if (statusId == 3) rowStr = "<span style=\"color:green;\">已发货</span>";
  else if (statusId == 4) rowStr = "<span style=\"color:black;\">已完成</span>";
  return rowStr;
}

function genOrderPayType(payTypeId){
  var rowStr = "";
  if (payTypeId == 1) rowStr = "微信";
  else if (payTypeId == 2) rowStr = "支付宝";
  else if (payTypeId == 3) rowStr = "货到付款";
  return rowStr;
}

function translateGoods(value){
	if (isBlank(value) || parseInt(value) <= 0) return "";
	var retVal = value;
	if (translateGoodses != null && translateGoodses != undefined && translateGoodses.length > 0){
		for(var i=0;i<translateGoodses.length;i++){
			if (translateGoodses[i].id == value) return translateGoodses[i].name;
		}
	}
	return retVal;
}

function translateListActiveGoodses(){
	var retVal = [];
	$.ajax({
		type:"post",
		url: "../custcontroller/goodsCustController/listActiveGoodses",
		dataType: 'json',
		async:false,
		success: function(data, textStatus) {
			debugger;
			if ( data.rows !=null ){
				retVal = data.rows;
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
	return retVal;
}

</script>
</html>
